//
//  FYVisitorTableViewControlle.swift
//  Weibo
//
//  Created by 冯毅 on 16/8/8.
//  Copyright © 2016年 冯毅. All rights reserved.
//

import UIKit

class FYVisitorTableViewControlle: UITableViewController {

    var isLogin:Bool = FYUserAccountViewModel.sharedUserAccount.isLogin
    
    var visitorView: FYVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func loadView() {
        if isLogin {
            super.loadView()
        } else {
            visitorView = FYVisitorView()
            
            visitorView?.loginClosure = { [weak self] in
                self?.reqeustOAuthVC()
            }
            
            view = visitorView
            
            setNavUI()
        }
    }
    
    private func setNavUI() {
    
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
    }
    
    @objc private func registerAction(){
        print("注册")
        
        reqeustOAuthVC()
    }
    
    @objc private func loginAction() {
        print("登录")
        
        reqeustOAuthVC()
    }
    private func reqeustOAuthVC() {
        let oAuthVC = FYOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuthVC)
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
}
